const app = getApp()
import { wxLogin } from '../../config/https'

Page({
  data: {
    logs: []
  },
  onGotUserInfo: function(e) {
    console.log(e)
    if (e.detail.userInfo != undefined) {
      let userInfo = JSON.stringify(e.detail.userInfo);
      let invitation_code = wx.getStorageSync('invitationCode')
      wx.login({
        success: res => {
          if (res.code) {
            wxLogin({
              code: res.code,
              userInfo,
              invitation_code
            }).then(suc => {
              if (suc.code == 1) {
                wx.setStorageSync('token', suc.data.token)
                wx.navigateBack()   //返回上一个页面
              } 
              app.$tip(suc.msg)
            })
          }
        }
      })
    }
  },
  onLoad: function () {
  }
})
